package com.cy.yqyquestion.demos.web.compnent;

import com.cy.yqyquestion.demos.web.vo.ContextBean;
import com.cy.yqyquestion.demos.web.vo.QueryVo;
import com.cy.yqyquestion.entity.Purchase;
import com.cy.yqyquestion.service.PurchaseService;
import com.ql.util.express.DefaultContext;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;
import lombok.extern.slf4j.Slf4j;
import com.yomahub.liteflow.core.FlowExecutor;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;

/**
 * @Author 朝闻道
 * @Date 2024年04月01日 10:02
 * @Description
 */
@Slf4j
@LiteflowComponent("addPurchase")
public class AddPurchase extends NodeComponent {


    @Resource
    private FlowExecutor flowExecutor;

    @Resource
    private PurchaseService purchaseService;
    @Override
    public void process() {
        //do your business
        log.info("启动【采购】流程");
        HashMap<String, String> requestData = this.getRequestData(); //LiteFlow 启动流程的初始参数
        log.info("【采购】流程初始参数：{}", requestData);

        Purchase purchase = new Purchase();
        purchase.setApplyTime(new Date());
        purchase.setApplyUser(requestData.get("user"));
        purchase.setName(requestData.get("purchase"));
        purchase.setPrice(new BigDecimal(requestData.get("price")));
        purchase.setStatus("提交采购申请完成");
        purchaseService.save(purchase);

        //将 采购记录 记录到 上下文
        ContextBean contextBean = this.getFirstContextBean();
        contextBean.setFinalResultChannel("提交环节");
        contextBean.addQueryVo(new QueryVo().setChannel("提交环节").setCount(10));

        log.info("【采购】申请提交");


    }
}
